import { reactive } from 'vue';
import { V_USER } from '@/api/url/erp/baseMessage';
import { getPurtcd, getArrivalInspect, arrivalInspectBatch, getjhd } from '@/api/url/erp/logisticDocuments';
import { sliceTime } from '@/utils/time';
export default function importConfig() {
  const base = reactive<any>({
    formData: {
      MF001: '', // 用户编号
      MF002: '', // 用户名称
      MF007: '', // 部门编号
      MODI_DATE: '', // 最后修改时间
    },
    columns: [
      {
        title: '盘点单ID',
        dataIndex: 'MF001',
        checked: true,
      },
      {
        title: '盘点单编号',
        dataIndex: 'MF002',
        checked: true,
      },
      {
        title: '盘点单名称',
        dataIndex: 'MF002',
        checked: true,
      },
      {
        title: '盘点日期',
        dataIndex: 'MF007',
        checked: true,
      },
      {
        title: '盘点人用户名',
        dataIndex: 'MF007',
        checked: true,
      },
      {
        title: '盘点人',
        dataIndex: 'MF001',
        checked: true,
      },
      {
        title: '盘点类型',
        dataIndex: 'MF007',
        checked: true,
      },
      {
        title: '仓库ID',
        dataIndex: 'MF001',
        checked: true,
      },
      {
        title: '仓库编码',
        dataIndex: 'MF002',
        checked: true,
      },
      {
        title: '单据状态',
        dataIndex: 'MF001',
        checked: true,
      },
      {
        title: '备注',
        dataIndex: 'MF002',
        checked: true,
      },
      {
        title: '操作',
        slotName: 'optional',
        fixed: 'right',
        width: 150,
        checked: true,
      },
    ],
    data: [],
    rules: {
      MF001: [
        {
          required: true,
          message: '请输入用户编号',
        },
      ],
      MF002: [
        {
          required: true,
          message: '请输入用户名称',
        },
      ],
      MF007: [
        {
          required: true,
          message: '请输入部门编号',
        },
      ],
    },
    config: ['add'],
    searchBar: '隐藏搜索',
    
    ModelTitle: '新增用户',
    visible: false, //遮罩层显示
    delVisible: false, //删除用户遮罩层
    delUserMsg: {},
    handleSubmit: null,
    upMsgIndex: 0, // 修改的下标
    selectFormData: {
      MF001: '', // 用户编号
      MF002: '', // 用户名称
      MF007: '', // 部门编号
      MF025: 'P'
    }, // 搜索表单
  });

  // 选择时间
  const onOk = (dateString, date) => {
    base.userFormData.MODI_DATE = dateString;
  };

  // 初始化userFormData
  const initUserFormData = {
    MF001: '',
    MF002: '',
    MF007: '',
    MODI_DATE: '',
  };
  const handleClick = () => {
    base.visible = true;
    base.userFormData = initUserFormData;
    base.ModelTitle = '新增用户';
  };

  // commit
  const handleBeforeOk = (done) => {
    base.handleSubmit.validate().then((res) => {
      if (!res) {
        console.log(base.upMsgIndex);
        if (base.upMsgIndex != null) {
          // 修改用户
          base.upMsgIndex = null;
        } else {
          // 添加用户
          // base.data.push(base.userFormData);
        }
        done();
      } else {
        done(false);
      }
    });
  };

  V_USER().then((res) => {
    console.log(res);
    if (res.code == 200 && res.data) {
      base.data = res.data.map((item) => {
        item.MODI_DATE = sliceTime(item.MODI_DATE);
        return item;
      });
    }
  });

  // 读取数据
  // getPurtcd({page: 1,pageSize: 8}).then(res => {
  //   console.log(res);
  // })

  // getArrivalInspect({page: 1,pageSize: 8}).then(res => {
  //   console.log(res);
  // })

  //   const param = {
  //     "accNumber": 0,
  //     "accPackageNumber": 0,
  //     "arrivePackageNumber": 0,
  //     "breakNumber": 0,
  //     "breakPackageNumber": 0,
  //     "creator": "",
  //     "dhdb": "",
  //     "dhdh": "",
  //     "remark": "测试",
  //     "returnNumber": 0,
  //     "returnPackageNumber": 0,
  //     "scrapNumber": 0,
  //     "scrapPackageNumber": 0,
  //     "xh": ""
  //   }

  //   arrivalInspectBatch(param).then(res => {
  //     console.log(res);
  //   })

  getjhd({ page: 1, pageSize: 8 }).then((res) => {
    console.log(res);
  });

  const handleCancel = () => {
    base.visible = false;
  };

  const upUser = (record, rowIndex) => {
    console.log(record);
    base.visible = true;
    base.ModelTitle = '修改用户信息';
    base.userFormData = record;
    base.upMsgIndex = rowIndex;
  };

  const delUser = (record) => {
    console.log(record);
    base.delVisible = true;
    base.delUserMsg = record;
  };

  // 确实删除页面删除
  const delHandleOk = () => {
    console.log('删除');
    console.log(base.delUserMsg);
    base.delVisible = false;
  };

  // 确实删除页面取消
  const delHandleCancel = () => {
    console.log('取消');
    base.delUserMsg = {};
    base.delVisible = false;
  };

  // 查询
  const selectDataMsg = () => {
    console.log(base.selectFormData);
  };

  // 重置SelectFormData
  const resetSelectFormData = () => {
    base.selectFormData.MF001 = '';
    base.selectFormData.MF002 = '';
    base.selectFormData.MF007 = '';
  };
  return {
    base,
    onOk,
    handleClick,
    handleBeforeOk,
    handleCancel,
    upUser,
    delUser,
    delHandleOk,
    delHandleCancel,
    selectDataMsg,
    resetSelectFormData,
  };
}
